
let box = document.getElementById('banner-right');
let screen = box.firstElementChild;
let ulObj = document.querySelector('#screen ul');
let lisObj = document.querySelectorAll('#screen ul li');
//let olObj = document.querySelector('#screen ol');
let arrObj = box.lastElementChild;
let leftbtn = arrObj.firstElementChild;
let rightbtn = arrObj.lastElementChild;
let times = '';

// lisObj.forEach((v,k)=>{
//     let olLi = document.createElement('li');
//     olLi.innerHTML = k+1;
//     k==0&&(olLi.className='current');
//     olObj.appendChild(olLi);
// })

box.onmouseover=function(){
    arrObj.style.display = 'block';
    clearInterval(times);
}
box.onmouseout=function(){
    arrObj.style.display='none';
    autoPlay();
}
//let ollisObj = olObj.children;
let imgW = screen.offsetWidth;
let imgIndex = 0;
let firstImgClone = lisObj[0].cloneNode(true);
ulObj.appendChild(firstImgClone);
rightbtn.onclick = function(){
    imgIndex++;
    let target = '';
    let onoff = false
    if (imgIndex==lisObj.length) {
        target = -imgW*imgIndex;
        imgIndex = 0;
        onoff = true;
    }else{
        target = -imgW*imgIndex;
    }
    move(ulObj,{left:target},function(){
        onoff&&(ulObj.style.left='0px');
    })
    // sel();
}
leftbtn.onclick = function(){
    imgIndex--;
    let target ='';
    if (imgIndex<0) {
        ulObj.style.left = -imgW * lisObj.length + 'px';
        imgIndex = lisObj.length-1;
        target = -imgW * imgIndex;
    }else{
        target = -imgW*imgIndex;
    }
    move(ulObj,{left:target},function(){

    })
    sel();
}

// olObj.onclick = function(eve){
//     let click = eve.target;
//     let target = '';
//     if (click.nodeName=='LI') {
//         imgIndex = click.innerHTML-1;
//         target = -imgW*imgIndex;
//     }
//     move(ulObj,{left:target},function(){

//     })
//     sel();
// }
function autoPlay(){
    times = setInterval(()=>{
        rightbtn.onclick();
    },2000)
}
autoPlay();
// function sel(){
//     let current = document.querySelector('.current');
//     current.classList.remove('current');
//     ollisObj[imgIndex].className = 'current';
// }



let navA = document.querySelectorAll('.sub dl a');
Array.from(navA).forEach(v=>{
    v.onclick = function(){
      window.location.href="../list.html"
    }
})

let buy = document.querySelector('#buy-bottom');
let buyObj = buy.children;
Array.from(buyObj).forEach(v=>{
    v.onclick = function(){
      window.location.href="../list.html"
    }
})

let sbot = document.querySelector('.s-bottom');
let sbotObj = sbot.children;
Array.from(sbotObj).forEach(v=>{
    v.onclick = function(){
      window.location.href="../list.html"
    }
})
let sbot1 = document.querySelector('.sb1');
let sbotObj1 = sbot1.children;
Array.from(sbotObj1).forEach(v=>{
    v.onclick = function(){
      window.location.href="../list.html"
    }
})
let sbot2 = document.querySelector('.sb2');
let sbotObj2 = sbot2.children;
Array.from(sbotObj2).forEach(v=>{
    v.onclick = function(){
      window.location.href="../list.html"
    }
})





// 秒杀
timeChange()
setInterval(function () {
  timeChange()
}, 1000)

function timeChange() {
  var timeSeckill = document.querySelector('.kill1 span:first-child');
  var d = new Date()
  var timeShow = document.querySelectorAll('.kill2 span');
  // setInterval(function () {
  var hours = Math.ceil((d.getHours() + 1) / 2) * 2;
  // console.log(hours);
  if (hours == 24) {
    timeSeckill.innerText = `00:00`
  } else {  
    if (hours >= 10) {
      timeSeckill.innerText = `${hours}:00`
    } else {
      timeSeckill.innerText = `0${hours}:00`
    }
  }
  var hoursNow = d.getHours();
  // console.log(hoursNow);

  //倒计时开始
  d.setHours(2); //未来未来两小时

  if (hoursNow % 2) {   //设置小时
    timeShow[0].innerText = '00'
  } else {
    timeShow[0].innerText = '01'
  }

  //设置分钟
  var showMinutes = 59 - d.getMinutes();
  // console.log(showMinutes);
  if (showMinutes >= 10) {
    timeShow[1].innerText = showMinutes;
  } else {
    timeShow[1].innerText = `0${showMinutes}`;
  }

  //设置秒
  var showSeconds = 59 - d.getSeconds();
  if (showSeconds >= 10) {
    timeShow[2].innerText = showSeconds;
  } else {
    timeShow[2].innerText = `0${showSeconds}`;
  }
}

let str='';
for(var i=0;i<goodsObj.length;i++){
  str+=`<li><img src="${goodsObj[i].img}" alt="">
  <p class="s-tit">${goodsObj[i].tit}</p>
<p class="s-pri"> 
  <span class="s-tag">¥</span>
  <span>${goodsObj[i].price}</span>
</p>
</li>`
}
var ss =document.querySelectorAll('.ss');
ss.forEach(v=>{
  v.innerHTML=str
})


//登陆信息
var userMsg = localStorage.getItem("userMsg")?JSON.parse(localStorage.getItem("userMsg")):{};
if(userMsg.isLogin === "ok"){
  $('#log').hide();
  $('#log1').show();
  $('#log1').find('span').html(userMsg.username);
}
$('#quit').click(function(){
  localStorage.setItem('userMsg','');
  location.reload();
})
$('#log1').find('span').click(function(){
  location.href='../center.html';
})